﻿/*
 *   TvDbDownloader: A util to download banners from http://thetvdb.com
 * 
 *   Copyright (C) 2010  Erlend Sand Bærland
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TvdbLib;
using System.IO;
using System.Threading;

namespace TVDBDownloader
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 1)
            {
                string strTVPath = args[0].ToString();
                bool bBanner = args.Contains("/banner");
                bool bPoster = args.Contains("/poster");
                bool bFanArt = args.Contains("/fanart");
                bool bClearLogo = args.Contains("/clearlogo");
                bool bClearArt = args.Contains("/clearart");
                DirectoryInfo dirTV = new DirectoryInfo(strTVPath);
                if (dirTV.Exists)
                {
                    foreach (DirectoryInfo dirSerie in dirTV.GetDirectories())
                    {
                        Downloader downloader = new Downloader(dirSerie.Name);
                        if (bBanner)
                            downloader.DownloadBanner(dirSerie, Downloader.BannerType.Banner);
                        if (bPoster)
                            downloader.DownloadBanner(dirSerie, Downloader.BannerType.Poster);
                        if (bFanArt)
                            downloader.DownloadBanner(dirSerie, Downloader.BannerType.FanArt);
                        if (bClearLogo)
                            downloader.DownloadBanner(dirSerie, Downloader.BannerType.Logo);
                        if (bClearArt)
                            downloader.DownloadBanner(dirSerie, Downloader.BannerType.ClearArt);
                        Thread.Sleep(1000); //Prevent flooding of server
                    }
                }
            }
            else
            {
                Console.WriteLine("Usage: TVDBDownloader.exe path [/banner] [/poster] [/fanart] [/clearlogo] [/clearart]");
            }
        }

    }
}
